package com.wanxi.controller.front;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.model.ProductType;
import com.wanxi.service.NewsTypeService;
import com.wanxi.service.ProductService;
import com.wanxi.vo.ProductVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("product")
@CrossOrigin(origins = "http://localhost:8081")
@RequestMapping("/product")
public class ProductController {
    @Autowired
    ProductService productService;

    @GetMapping("/find")
    public String findEnableProduct(ProductVO productVO,
                                    @Param("productTypeID") String productTypeID){
        productVO.setProductType(ProductType.builder().id(productTypeID).build());
        ResultDTO product = productService.findProduct(productVO);
        return JSONObject.toJSONString(product);
    }
}
